package com.qf.day05;

import java.util.Random;

public class Cat {

    String kind;   // 品种
    String color;
    int year;      // 年龄
    String name;
    String sex;
    int happy;
    double weight;

    public  Cat() {
        this.kind = "缅因";
        this.color = "gray";
        this.year = 3;
        this.name = "坤坤";
        this.sex = "雄性";
        this.happy = 50;
        this.weight = 20;
    }

    public Cat(String name){
        this.name = name;
    }

    public Cat(String kind, String color, int year, String name, String sex, int happy, double weight) {
        this.kind = kind;
        this.color = color;
        this.year = year;
        this.name = name;
        this.sex = sex;
        this.happy = happy;
        this.weight = weight;
    }


    public void eat(){

        this.happy += 10;
        System.out.println("心情值+10="+happy);
    }
    public  void  sleep(){
        this.happy += 10;
        System.out.println("心情值+10="+happy);
    }
    public  void  fish(){
        this.happy += 10;
        this.weight += 2;
        System.out.println("心情值+10="+happy);
        System.out.println("体重值+2="+weight);
    }
    public void  backflip(){
        System.out.println(name+"后空翻");
        this.weight -= 1;
        this.happy += 5;
        System.out.println("心情+5="+happy);
        System.out.println("体重-1="+weight);

    }
    public void bubble(int[] array){
        int n = array.length;
        for (int i = 1; i < n ; i++) {
            for (int j = 0; j < n - i ; j++) {
                if (array[j] > array[j + 1]) {
                    // 交换相邻元素的位置
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }

    // 静态方法
    public static Cat randomCat(){
        Cat cat = new Cat();
        String[] names = {"小叮当","tom","加菲","HelloKitty","坤坤"};
        Random random = new Random();
        int index = random.nextInt(names.length); // [0,4]
        cat.name = names[index];
        cat.sex = random.nextInt(2)>0?"男":"女";
        cat.weight = random.nextInt(100);
        cat.happy = random.nextInt(100);
        cat.year = 1+random.nextInt(5);
        return cat;
    }


//    public String printCat(){
//
//    }

    @Override
    public String toString() {
        return "Cat{" +
                "kind='" + kind + '\'' +
                ", color='" + color + '\'' +
                ", year=" + year +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", happy=" + happy +
                ", weight=" + weight +
                '}';
    }
}
